import { getOrder } from "@/api/order";
Page({
  // 页面的初始数据
  data: {
    orderList: [],
    page: 1,
    limit: 10,
    total: 0,
  },

  // 获取订单列表
  async getOrder() {
    const { data } = await getOrder({
      page: this.data.page,
      limit: this.data.limit,
    });
    console.log("订单列表=》", data);
    if (data.code === 200) {
      this.setData({
        orderList: [...this.data.orderList, ...data.data.records],
        total: data.data.total,
      });
    }
  },

  // 监听页面的上拉加载
  onReachBottom() {
    const { page } = this.data;
    if (this.data.orderList.length < this.data.total) {
      this.setData({
        page: page + 1,
      });
      this.getOrder();
    }
  },

  // 监听页面的下拉刷新操作
  onPullDownRefresh() {
    this.setData({
      orderList: [],
      total: 0,
      page: 1,
    });
    this.getOrder();
    wx.stopPullDownRefresh();
  },

  onShow() {
    this.getOrder();
  },
});
